﻿using System.Drawing;
using System.Windows.Forms;
using DACU.Properties;

namespace DACU.Tools.WebBrowser
{
	class BrowserTools : Form
	{
		public event WebBrowserNavigatedEventHandler Navigated;

		readonly System.Windows.Forms.WebBrowser _browser = new System.Windows.Forms.WebBrowser();

		public BrowserTools()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            SuspendLayout();
            _browser.Dock = DockStyle.Fill;
            _browser.Name = "_browser";
            //browser.ScrollBarsEnabled = false;
            _browser.Size = new Size(417, 300);
            _browser.TabIndex = 0;
			Controls.Add(_browser);
			_browser.Navigated += LoginBrowser_Navigated;
			//Shown += LoginWnd_Shown;
            ClientSize = new Size(417, 300);
        	FormBorderStyle = FormBorderStyle.SizableToolWindow;
            Name = "BrowserTools";
            StartPosition = FormStartPosition.CenterParent;
            Text = Resources.BrowserTools_Autherization;
            ResumeLayout(false);
        }

		public void Show(string url)
		{
			_browser.Navigate(url);
			ShowDialog();
			Visible = false;
		}

		private void LoginBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
		{
			if (e.Url.LocalPath.EndsWith("login.php"))
				Visible = true;
			if (Navigated != null)
				Navigated(sender, e);
		}
	}
}
